<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="品名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入品名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="款号" prop="itemNum">
        <el-input
          v-model="queryParams.itemNum"
          placeholder="请输入款号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="尺码" prop="sizeNum">
        <el-input
          v-model="queryParams.sizeNum"
          placeholder="请输入尺码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      
      <el-form-item label="返货日期" prop="returnDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.returnDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择返货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="returnstockrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" v-if="false" align="center" prop="id" />
      <el-table-column label="返货日期" align="center" prop="returnDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returnDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品名" align="center" prop="name" />
      <el-table-column label="款号" align="center" prop="itemNum" />
      <el-table-column label="尺码" align="center" prop="sizeNum" />
      <!-- <el-table-column label="返货数量" align="center" prop="count" /> -->
      <el-table-column :label=sumLable align="center" prop="count" />
      <el-table-column label="是否有效 " align="center" prop="effect">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_effect" :value="scope.row.effect"/>
        </template>
      </el-table-column>
      
      
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listCount,listReturnstockrecord, getReturnstockrecord, delReturnstockrecord, addReturnstockrecord, updateReturnstockrecord, exportReturnstockrecord } from "@/api/system/returnstockrecord";
import moment from 'moment'
export default {
  name: "Returnstockrecord",
   dicts: ['sys_discount_value','sys_effect'],
  data() {
    return {
       //库存总数量lable
      stockSum: null,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 返货记录表格数据
      returnstockrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        itemNum: null,
        sizeNum: null,
        count: null,
        effect: null,
        returnDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getCount();
  },
  methods: {
    getCount() {
      this.loading = true;
      listCount(this.queryParams).then(response => {
        console.log(response.data);
        this.stockSum = response.data;
        
        this.loading = false;
      });
    },
    /** 查询返货记录列表 */
    getList() {
      this.loading = true;
      listReturnstockrecord(this.queryParams).then(response => {
        this.returnstockrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        itemNum: null,
        sizeNum: null,
        count: null,
        effect: null,
        returnDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getCount();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加返货记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReturnstockrecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改返货记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReturnstockrecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.getCount();
            });
          } else {
            addReturnstockrecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.getCount();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除返货记录编号为"' + ids + '"的数据项？').then(function() {
        return delReturnstockrecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有返货记录数据项？').then(() => {
        this.exportLoading = true;
        return exportReturnstockrecord(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  },
   computed:{
    sumLable() {
      return '返货量(总件：'+this.stockSum+ ')'
    }

  }
};
</script>
